package com.cncf.controller.user;

import com.cncf.entity.Enterprise;
import com.cncf.entity.FirstReportView;
import com.cncf.entity.ReportInfo;
import com.cncf.entity.ReportInfoWithBLOBs;
import com.cncf.response.ResponseData;
import com.cncf.service.FirstReportViewService;
import com.cncf.util.TokenConfig;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zj
 */
@Api(value = "User", description = "检验报告的查询")
@Controller
@RequestMapping("/user/firstReportView")
public class UserFirstReportViewController {
    @Autowired
    private FirstReportViewService firstReportViewService;

    @ApiOperation(value = "通过id获取报告信息", notes = "全部字段")
    @RequestMapping(value = "selectFirstReportViewById/{id}", method = {RequestMethod.GET})
    @ResponseBody
    public ResponseData<FirstReportView> selectFirstReportViewById(@ApiParam("报告id") @PathVariable String id) {
        return firstReportViewService.selectFirstReportViewById(id);
    }

    @ApiOperation(value = "分页查询所有报告信息", notes = "不传值不分页")
    @RequestMapping(value = "selectAllFirstReportViewByPage", method = {RequestMethod.GET})
    @ResponseBody
    public ResponseData<List<FirstReportView>> selectAllFirstReportViewByPage(
            @ApiParam("page") @RequestParam(value = "page", required = false) Integer page,
            @ApiParam("pageSize") @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        return firstReportViewService.selectAllFirstReportViewByPage(page, pageSize);
    }

    @ApiOperation(value = "模糊查询报告的简要信息", notes = "")
    @RequestMapping(value = "fuzzySearchFirstReportView", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseData<List<FirstReportView>> fuzzySearchFirstReportView(
            @ApiParam("报告编号") @RequestParam(value = "reportNumber", required = false) String reportNumber,
            @ApiParam("产品名称") @RequestParam(value = "productName", required = false) String productName,
            @ApiParam("生产单位") @RequestParam(value = "productUnit", required = false) String productUnit) {
        return firstReportViewService.fuzzySearch(reportNumber, productName, productUnit);
    }

/*    @ApiOperation(value = "根据token中对应的企业查询报告的简要信息",
            notes = "从token取出登录信息，得到用户登录的是哪个企业的公用账号，然后查出这个企业的所有的产品的报告列表")
    @RequestMapping(value = "searchFirstReportViewByEnterprise", method = {RequestMethod.GET})
    @ResponseBody
    public ResponseData<List<FirstReportView>> searchFirstReportViewByEnterprise(HttpServletRequest request) {
        Enterprise enterprise = (Enterprise) request.getAttribute(TokenConfig.DEFAULT_USERID_REQUEST_ATTRIBUTE_NAME);
        return firstReportViewService.fuzzySearch(null, null, enterprise.getEnterpriseName());
    }*/

}
